﻿/*-----------------------------------------------
// File: LoginResUpdate.cs
// Description: 
// Author: Shaobing	492057342@qq.com
-----------------------------------------------*/
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Login;


public class LoginAuth : Fsm.FsmStateMonoBase<Login.LoginState>
{
    LoginManager manager
    {
        get { return this.controller as LoginManager; }
    }

    public LoginAuth(Login.LoginState state, Login.LoginManager ctrl) : base(state, ctrl)
    {
    }

    public override void Enter()
    {
        Auth();
        manager.loginUI.HideUpdateUI();
    }

    void Auth()
    {
        if (GameConfig.Instance.platform == 1)
        {
            manager.loginUI.loginNormalPanel.Show();
            // 不走SDK
            if (string.IsNullOrEmpty(StaticData.UserName) || string.IsNullOrEmpty(StaticData.PassWord))
            {
                // 没有缓存的用户名和密码
                manager.loginUI.loginNormalPanel.ShowInternalAccountPanel();
            }
            else
            {
                LoginAuthPass();
            }
        }
		#if !NAKED
        else if (GameConfig.Instance.platform == 2)
        {
            if (GameConfig.Instance.isSwitch)
            {
                manager.loginUI.loginNormalPanel.Show();
                //调用了切换账号，就不走登录了
                LoginAuthPass();
                return;
            }
            else
            {
                // TODO 走SDK

                if (GameConfig.Instance.GetChannelId == ChannelId.YingYongBao)
                {
                    manager.loginUI.loginNormalPanel.Show(true);
                    
                }
                else
                {
                    manager.loginUI.loginNormalPanel.Show();
                    if (string.IsNullOrEmpty(StaticData.UserName)||string.IsNullOrEmpty(StaticData.PassWord))
                    {
                        PlatformSDK.GetInstance().Login(manager); 
                    }
                    
                }

            }

        }
		#endif
    }






    public void LoginAuthPass()
    {
        Debug.Log("[DEBUG] LoginAuthPass time = " + ServerTimerTool.ClientJavaTime());
        Debug.Log("LoginAuthPass GetServer");
        manager.isAuthPassed = true;
        if (GameConfig.Instance.GetChannelId == ChannelId.YingYongBao)
        {
            manager.loginUI.loginNormalPanel.Show(true);

        }
        else
        {
            manager.loginUI.loginNormalPanel.Show();
        }
        if (string.IsNullOrEmpty(StaticData.UserName) || string.IsNullOrEmpty(StaticData.PassWord))
        {
            manager.isAuthPassed = false;
            manager.loginUI.HideServerPanel();
            PlatformSDK.GetInstance().Login(manager);
          
        }
        else
        {
            this.controller.SwitchState(LoginState.GetServerList);
        }
        
    }
}